package com.example.ucs_alg_node_manager.controller;

import com.example.ucs_alg_node_manager.domain.Node;
import com.example.ucs_alg_node_manager.dto.NodeDTO;
import com.example.ucs_alg_node_manager.dto.QueryDTO;
import com.example.ucs_alg_node_manager.service.NodeService;
import com.example.ucs_alg_node_manager.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/node")
@CrossOrigin
@Api("节点功能管理")
public class NodeController {

    @Resource
    private NodeService nodeService;

    @ApiOperation("查询节点列表")
    @PostMapping("/query")
    public ReturnVO query(@RequestBody QueryDTO dto){
        return nodeService.getNodes(dto);
    }

    @ApiOperation("根据节点名称查询节点信息")
    @GetMapping("/queryByName")
    public ReturnVO queryByName(@RequestParam("name")String name){
        return nodeService.getNodeByName(name);
    }

    @ApiOperation("添加节点信息")
    @PostMapping("/create")
    public ReturnVO create(@RequestBody NodeDTO dto){
        return nodeService.addNode(dto);
    }

    @ApiOperation("删除节点信息")
    @GetMapping("/remove")
    public ReturnVO remove(@RequestParam("id")Integer id){
        return nodeService.delNode(id);
    }

    @ApiOperation("修改节点信息")
    @PostMapping("/update")
    public ReturnVO update(@RequestBody Node node){
        return nodeService.update(node);
    }

    @ApiOperation("设置节点状态")
    @GetMapping("/setStatus")
    public ReturnVO setStatus(@RequestParam("nodeId")Integer nodeId,
                              @RequestParam("status")String type){
        return nodeService.setNode(nodeId, type);
    }


}
